package com.yp.infrastructure.axon.handler;

import com.yp.infrastructure.axon.constants.EnumErrorMessage;
import com.yp.infrastructure.axon.exception.AxonException;
import com.yp.infrastructure.axon.model.BaseAggregate;
import org.axonframework.eventsourcing.EventSourcingRepository;

public abstract class BaseQueryHandler extends AbstractAxonHandler {

    protected <T extends BaseAggregate> T getAggregate(EventSourcingRepository<T> repository, String id, boolean e) {
        T t = repository.load(id).getWrappedAggregate().getAggregateRoot();
        if (e && null == t) {
            throw new AxonException(EnumErrorMessage.AGGREATE_NOT_FOUND);
        }
        return t;
    }
}
